import imaplib

def isLoginValid(username, password):
	try:
		imapSession = imaplib.IMAP4_SSL('imap.gmail.com')
		typ, accountDetails = imapSession.login(username, password)
		if typ != 'OK':
			raise
			return False
		else:
			imapSession.logout()
			return True
	except:
		return False